package com.ja.openchat.ui.found;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.ja.openchat.R;
import com.lxj.xpopup.core.AttachPopupView;
import com.lxj.xpopup.util.XPopupUtils;
import com.zy.openchat.core.model.circle.CircleTopicInfo;

import java.util.List;

public class CircleTopicAttachDialog extends AttachPopupView {

    private OnItemSelectListener<CircleTopicInfo> mListener;
    private List<CircleTopicInfo> mTopicInfos;
    public CircleTopicAttachDialog(@NonNull Context context) {
        super(context);
    }
    public void setTopicInfos(List<CircleTopicInfo> topicInfos){
        this.mTopicInfos = topicInfos;
    }

    public void setListener(OnItemSelectListener<CircleTopicInfo> listener){
        this.mListener = listener;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        CircleTopicAdapter circleTopicAdapter = new CircleTopicAdapter(mTopicInfos);
        recyclerView.setAdapter(circleTopicAdapter);
        circleTopicAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                if(mListener!=null){
                    mListener.onItemSelect(circleTopicAdapter.getItem(position),position);
                }
                dismiss();
            }
        });
    }


    @Override
    protected int getPopupWidth() {
        return XPopupUtils.getAppWidth(getContext());
    }

    @Override
    protected int getMaxWidth() {
        return XPopupUtils.getAppWidth(getContext());
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_circle_top_attach_popu;
    }
}
